c# linq where value is max and one item

85

getting the row of max value c# linq -

var result = table.OrderByDescending(x => x.Status).First();

c# linq where value is max and one item -

    public static T FirstWithMax<T, TValue>(this IEnumerable<T> items, Func<T, TValue> propSelector)
        where TValue : IComparable<TValue>
    {
        return items.Aggregate((current, next) => propSelector.Invoke(current).CompareTo(propSelector.Invoke(next)) < 0 ? next : current);
    }

Comments

Submit
0 Comments